package com.iogogogo.tenant.api;

import com.iogogogo.tenant.common.base.BaseResult;
import com.iogogogo.tenant.common.wrapper.ResponseWrapper;
import com.iogogogo.tenant.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by tao.zeng on 2021/8/8.
 */
@RestController
@RequestMapping("/api/user")
public class UserApi implements BaseResult {

    private final UserService userService;

    public UserApi(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/{userId}")
    public ResponseWrapper<?> user(@PathVariable("userId") Long userId) {
        return ok(userService.findById(userId));
    }


    @GetMapping
    public ResponseWrapper<?> users() {
        return ok(userService.findAll());
    }
}
